package edu.hitsz.aircraft;

import edu.hitsz.application.Main;
import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.bullet.EnemyBullet;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class EliteEnemy extends AbstractAircraft {
    /** 子弹伤害 */
    private int power = 10;
    /** 射击方向（向下） */
    private int direction = 1;
    /** 射击周期(ms) */
    private int shootInterval = 1000;
    /** 上次射击时间 */
    private long lastShootTime = 0;

    public EliteEnemy(int locationX, int locationY, int speedX, int speedY, int hp) {
        super(locationX, locationY, speedX, speedY, hp);
    }

    @Override
    public void forward() {
        super.forward();
        // 超出屏幕消失
        if (locationY >= Main.WINDOW_HEIGHT) {
            vanish();
        }
    }

    @Override
    public List<BaseBullet> shoot() {
        List<BaseBullet> res = new LinkedList<>();
        long currentTime = System.currentTimeMillis();
        if (currentTime - lastShootTime >= shootInterval) {
            lastShootTime = currentTime;
            int x = getLocationX();
            int y = getLocationY() + direction * 2;
            int speedY = getSpeedY() + direction * 5;
            // 直射子弹
            BaseBullet bullet = new EnemyBullet(x, y, 0, speedY, power);
            res.add(bullet);
        }
        return res;
    }
}